package com.heu.picture.controller;


import com.heu.picture.common.BaseResponse;
import com.heu.picture.common.ResultUtils;
import com.heu.picture.request.UserLoginRequest;
import com.heu.picture.request.UserRegisterRequest;
import com.heu.picture.response.UserLoginResponse;
import com.heu.picture.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author Dong & Fei
 * @since 2025-02-20
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("/register")
    public BaseResponse<Void> register(@RequestBody UserRegisterRequest userRegisterRequest) {
        userService.register(userRegisterRequest);
        return ResultUtils.success();
    }

    @PostMapping("/login")
    public BaseResponse<UserLoginResponse> login(@Validated @RequestBody UserLoginRequest request, HttpServletRequest httpServerRequest, HttpServletResponse httpServletResponse){
        return ResultUtils.success(userService.login(request, httpServerRequest, httpServletResponse));
    }


}
